<%--
  Created by IntelliJ IDEA.
  User: JiangMingda
  Date: 2022/8/17
  Time: 17:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>商品列表</title>
    <!-- 引入vue.js -->
    <script src="${pageContext.request.contextPath}/static/js/vue.min.js" type="text/javascript"></script>
    <!-- 解决浏览器生产提示信息 -->
    <script> Vue.config.productionTip = false </script>
    <!-- jquery.js -->
    <script src="${pageContext.request.contextPath}/static/js/jquery-2.1.1.min.js" type="text/javascript"></script>
    <!-- 引入组件库 -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ElementUI/index.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/js/ElementUI/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-form ref="form" :model="goods" label-width="80px">
        <el-form-item label="商品名称">
            <el-input v-model="goods.goodsName"></el-input>
        </el-form-item>
        <el-form-item label="数量">
            <el-input v-model="goods.goodsNumber"></el-input>
        </el-form-item>
        <el-form-item label="单价/元">
            <el-input v-model="goods.goodsPrice"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="insertGoods">新增商品</el-button>
        </el-form-item>
    </el-form>
</div>
<script>
    new Vue({
        el:'#app',
        data:{
            goods:{
                goodsName:"",
                goodsNumber:"",
                goodsPrice:""
            }
        },
        methods:{
            insertGoods(){
                var _this = this;
                $.ajax({
                    url:'${pageContext.request.contextPath}/goods/goods',
                    dataType:'json',
                    type:'post',
                    data:{
                        goodsName:this.goods.goodsName,
                        goodsNumber:this.goods.goodsNumber,
                        goodsPrice:this.goods.goodsPrice
                    },
                    success:function (rs) {
                        if (rs.code == 200){
                            _this.$alert(rs.msg+"正在返回商品列表")
                            setTimeout(function () {
                                location.href = '${pageContext.request.contextPath}/goodsList';
                            },1500)
                        }else {
                            _this.$alert(rs.msg)
                        }
                    }
                })
            }
        },
        mounted(){
        }
    })
</script>
</body>
</html>
